//Cristian Moral Martos

package Ejercicio11;

import utils.ImagePGM;

/**
 * 
 * 
 Exercise 11.1 Implement the function imWatershed following the pseudocode
 * proposed in the paper: "Watersheds in Digital Spaces: An Efficient Algorithm
 * Based on Immersion Simulations", L. Vincent y P.Soille, IEEE Transactions on
 * Pattern Analysis and Machine Intelligence, Vol. 13, Nro. 6, June, 1991.
 * 
 * imWatershed (imageIn, conectividad, imageOut) // flooding of gradient image
 * imageIn
 * 
 * Note: internally, an auxiliary image of enough bit depth should be used (at
 * least 16 bits, or, better, 32 bits per pixel)
 * 
 * The output of the function is the wathershed (borders of the catchment
 * bassins)
 * 
 * To check the function, using the modified gradient image
 * micro24_20060309_grad_mod.pgm as input image, imWatershed should obtain a
 * similar result to that in image micro24_20060309_grad_mod_wat.pgm.
 * 
 * Note: the paragraph in the paper after the pseudocode contains some aspects
 * and operations that should be considered and that are part of the algorithm
 * 
 * Note: eight connectivity can be assumed.
 * 
 * The following images are attached: -micro24_20060309_grad_mod.pgm: modified
 * gradient (markers have been used) -micro24_20060309_grad_mod_wat.pgm:
 * watershed of the modified gradient micro24_20060309_grad_mod.pgm .
 * 
 * Note: this result has been computed using an algorithm somewhat different
 * from that in the paper by Vincent-Soille (using in fact hierarchical queues),
 * so there can be small variations in the watershed lines.
 * 
 */
public class Ejercicio111 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String pathInputImageWatershed = "input\\micro24_20060309_grad_mod.pgm";
		ImagePGM inputImageWatershed = new ImagePGM(pathInputImageWatershed);

		// String pathComprobacionImageWatershed =
		// "input\\micro24_20060309_grad_mod_wat.pgm";
		// ImagePGM comprobacionImageWatershed = new
		// ImagePGM(pathComprobacionImageWatershed);

		String pathOutputImageWatershed = "output\\micro24_20060309_grad_mod_watershed.pgm";
		ImagePGM outputImageWatershed = inputImageWatershed.getWatershed();
		outputImageWatershed.imageToFile(pathOutputImageWatershed);

		System.out
				.println("La imagen " + pathInputImageWatershed
						+ " tiene como watershed la imagen "
						+ pathOutputImageWatershed);

	}

}
